import requests
import json
from liebiaowang import get_city
host_url = "http://127.0.0.1:8008"

def create_city(city_data):
    url = "{}/citys/".format(host_url)
    city_data = json.dumps(city_data)  # 把字典转成json格式
    headers = {
        'Content-Type': "application/json",
        'cache-control': "no-cache",
    }

    response = requests.request("POST", url, data=city_data, headers=headers)
    print("数据已插入: ", response.text)


if __name__ == '__main__':
    city_list = get_city()
    for c in city_list:
        create_city(city_data=c)


